#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "simplebanner.h"
#include "callbacksimplebanner.h"
#include <QtCore/QCoreApplication>
#include "AdInterstitialForm.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::setOrientation(ScreenOrientation orientation)
{
#if defined(Q_OS_SYMBIAN)
    // If the version of Qt on the device is < 4.7.2, that attribute won't work
    if (orientation != ScreenOrientationAuto) {
        const QStringList v = QString::fromAscii(qVersion()).split(QLatin1Char('.'));
        if (v.count() == 3 && (v.at(0).toInt() << 16 | v.at(1).toInt() << 8 | v.at(2).toInt()) < 0x040702) {
            qWarning("Screen orientation locking only supported with Qt 4.7.2 and above");
            return;
        }
    }
#endif // Q_OS_SYMBIAN

    Qt::WidgetAttribute attribute;
    switch (orientation) {
#if QT_VERSION < 0x040702
    // Qt < 4.7.2 does not yet have the Qt::WA_*Orientation attributes
    case ScreenOrientationLockPortrait:
        attribute = static_cast<Qt::WidgetAttribute>(128);
        break;
    case ScreenOrientationLockLandscape:
        attribute = static_cast<Qt::WidgetAttribute>(129);
        break;
    default:
    case ScreenOrientationAuto:
        attribute = static_cast<Qt::WidgetAttribute>(130);
        break;
#else // QT_VERSION < 0x040702
    case ScreenOrientationLockPortrait:
        attribute = Qt::WA_LockPortraitOrientation;
        break;
    case ScreenOrientationLockLandscape:
        attribute = Qt::WA_LockLandscapeOrientation;
        break;
    default:
    case ScreenOrientationAuto:
        attribute = Qt::WA_AutoOrientation;
        break;
#endif // QT_VERSION < 0x040702
    };
    setAttribute(attribute, true);
}

void MainWindow::showExpanded()
{
#ifdef Q_OS_SYMBIAN
    showFullScreen();
#elif defined(Q_WS_MAEMO_5)
    showMaximized();
#else
    show();
#endif
}

void MainWindow::on_CloseButton_clicked()
{
    exit(0);
}

void MainWindow::on_SimpleBannerButton_clicked()
{
    simpleBanner* sb = new simpleBanner();
    sb->setWindowState(sb->windowState() | Qt::WindowFullScreen);
    sb->exec();
    delete sb;
}

void MainWindow::on_InterstitualButton_clicked()
{
    AdInterstitialForm* iForm = new AdInterstitialForm();
    iForm->getControl()->set_Site("8061");
    iForm->getControl()->set_Zone("16112");
    iForm->getControl()->set_MinSizeX(300);
    iForm->getControl()->set_MinSizeY(300);
    iForm->setCloseButtonShowTime(5);
    QPushButton* button = new QPushButton(iForm);
    button->setText("Close");
    iForm->setCloseButton(button);
    iForm->setWindowState(iForm->windowState() | Qt::WindowFullScreen);
    iForm->exec();

    delete iForm;
}

void MainWindow::on_CallBackButton_clicked()
{
    callbacksimplebanner* sb = new callbacksimplebanner();
    sb->setWindowState(sb->windowState() | Qt::WindowFullScreen);
    sb->exec();
    delete sb;
}
